import Vue from 'vue';
import Vuex from 'vuex'
import axios from 'axios'
import {
    nanoid
} from 'nanoid';
Vue.use(Vuex);

const actions = {
    addSaying(miniStore, value) {
        axios.get('http://api.uixsj.cn/hitokoto/get?type=social').then(
            response => {
                miniStore.commit('ADD_SAYING', {id: nanoid(), title: response.data});
            },
            err => {
                alert(err);
            }
        )
    }
}

const mutations = {
    INCREMENT_SCHOOL_AGE(state, value) {
        state.School.age += value;
    },
    ADD_SAYING(state, value) {
        state.SayingList.unshift(value);
    }
}

const state = {
    School: {
        name: '亮亮课堂',
        address: '平西府村',
        tel: '17831191216',
        age: 3
    },
    SayingList: [{
        id: 'fsadfa',
        title: '你滴韩王'
    }]
}

const getters = {

}

export default new Vuex.Store({
    actions,
    mutations,
    state,
    getters
})